﻿@using winproject.Models;
@{
    ViewBag.Title = "Product - Properties | Software-Kart.com";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

    int resCode = 0;
    ProductProperties oItemEditDetail = null;
    if (ViewData != null && ViewData.Keys.Count() > 0 && ViewData.Keys.Contains("resCode"))
    {
        resCode = Convert.ToInt32(ViewData["resCode"]);
    }
    if (resCode == 250)
    {
        oItemEditDetail = (ProductProperties)ViewData["resData"];
    }
    
}

@Styles.Render("~/Content/Vendors")
<link type="text/css" rel="stylesheet" href="~/Content/css/jquery-te-1.4.0.css">
<script type="text/javascript" src="~/Scripts/jquery-te-1.4.0.js" charset="utf-8"></script>
@*<script type="text/javascript" src="js/jquery-1.9.0.js"></script>*@
<script type="text/javascript" src="~/Scripts/ajaxupload.3.5.js"></script>
<script type="text/javascript" src="~/Scripts/ieajaxupload.js"></script>
@Html.Partial("_LeftMenu")


<!-- content -->
<div class="col-md-10">
    
    <div class="row">
        <div class="panel panel-default bootstrap-admin-no-table-panel">
            <div class="row">
                <div class="col-md-9 text-left">
                    <ol class="breadcrumb">
                      <li><a href="#">Category</a></li>
                      <li><a href="#">Subcategory</a></li>
                      <li class="active">Product: Title</li>
                    </ol> 
                </div>
            </div>
            <div class="panel-heading">
                <div class="text-muted bootstrap-admin-box-title">Product > Properties</div>
            </div>
            <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                <form id="frmProdProperties" action="~/Products/AddProductProperty"  method="post" enctype="multipart/form-data" >
                    @{
                        if (oItemEditDetail != null && (oItemEditDetail.nPid) > 0)
                        {
                            <input type="hidden" id="txtUniqueId" name="txtUniqueId" value="@oItemEditDetail.nPid" />
                        }
                          else{
                            <input type="hidden" id="txtUniqueId" name="txtUniqueId" value="@ViewData["pid"]" />   
                          }
                     }
                <table width="100%"  cellpadding="5" class="table-striped">
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter TOC Link
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sTocLink))
                                {
                                    <input type="text" id="txtTocLink" name="txtTocLink" value="@oItemEditDetail.sTocLink.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtTocLink" name="txtTocLink" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Eula Link
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sEulaLink))
                                {
                                    <input type="text" id="txtEulaLink" name="txtEulaLink" value="@oItemEditDetail.sEulaLink.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtEulaLink" name="txtEulaLink" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Exe-Name
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sExeName))
                                {
                                    <input type="text" id="txtExeName" name="txtExeName" value="@oItemEditDetail.sExeName.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtExeName" name="txtExeName" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter MD5CheckSum
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sMD5CheckSum))
                                {
                                    <input type="text" id="txtMD5CheckSum" name="txtMD5CheckSum" value="@oItemEditDetail.sMD5CheckSum.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtMD5CheckSum" name="txtMD5CheckSum" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter File Size(bytes)
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.nSizeInBytes)>0)
                                {
                                    <input type="text" id="txtFilesSize" name="txtFilesSize" value="@oItemEditDetail.nSizeInBytes" />
                                }
                                else
                                {
                                    <input type="text" id="txtFilesSize" name="txtFilesSize" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Author Name
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sAuthorName))
                                {
                                    <input type="text" id="txtAuthorName" name="txtAuthorName" value="@oItemEditDetail.sAuthorName.Trim()" />
                                }
                                else
                                {
                                    <input type="text" id="txtAuthorName" name="txtAuthorName" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <table>
                                <tr>
                                    <td>
                                        Digital Signed
                                    </td>
                                    <td>
                                        @{
                                            if (oItemEditDetail != null && (oItemEditDetail._isDigitalSigned==true))
                                            {
                                                <input type="checkbox" id="chkExeSigned" name="chkExeSigned" checked="checked"/>
                                            }
                                            else
                                            {
                                                <input type="checkbox" id="chkExeSigned" name="chkExeSigned" />
                                            }
                                        }
                                        
                                    </td>
                                    <td>
                                        Multilingual
                                    </td>
                                    <td>
                                        @{
                                            if (oItemEditDetail != null && (oItemEditDetail._isMultilingual==true))
                                            {
                                                <input type="checkbox" id="chkMultilingual" name="chkMultilingual" checked="checked"/>
                                            }
                                            else
                                            {
                                                <input type="checkbox" id="chkMultilingual" name="chkMultilingual" />
                                            }
                                        }
                                        
                                    </td>
                                </tr>
                            </table>

                        </td>
                        
                    </tr>
                    
                    <tr>
                        <td colspan="2">
                            &nbsp;
                        </td>
                        <td class="text-left">
                           <ul id="html5_uploader_filelist" class="plupload_filelist"></ul> <br>
                           <div id="upload" class="plupload_buttons sharingActionButons" style="display:block !important;background-color:burlywood;border-radius:10px 0px 0px 10px;border-radius: 10px 10px 10px 10px;width: 95px;padding: 4px;">Choose Files</div>
                        </td>
                    </tr>


                    <tr>
                        <td colspan="2">
                            &nbsp;
                        </td>
                        <td class="text-left">
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.nPid) > 0)
                                {
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Save">Save</button>
                                }
                                else
                                {
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Add">Add</button>
                                }
                            }
                            &nbsp; &nbsp;
                            <button type="button" id="cmdCancel" name="cmdSave" value="Cancel" onclick="window.location.href='@HttpContext.Current.Request.ApplicationPath/Admin/SubCategory'">Cancel</button>
                        </td>
                    </tr>
                </table>
                </form>
            </div>
        </div>
    </div>
    
</div>

<script type="text/javascript">
    $(function () {
        var btnUpload = $('#upload');
        var status = $('#status');
        new AjaxUpload(btnUpload, {
            action: 'AddProductImages',
            name: 'fileImgPath',
            onSubmit: function (file, ext) {

                //                if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
                //                    // extension is not allowed 
                //                    status.text('Only JPG, PNG or GIF files are allowed');
                //                    return false;
                //                }
                //newly added
                fileuploadrequest_c++;
                var uploadFileCounter = "uploadc-" + fileuploadrequest_c;
                var UploadingList = "<div id='" + uploadFileCounter + "'>" + file + "</div>";

                this.setData({ X_FILENAME: fileuploadrequest_c, X_PRODID: $("#txtUniqueId").val(), X_COUNTER: fileuploadrequest_c });
                //add row for processing
                var fsize = "   -";
                //alert(file);
                //alert("on submit: " + uploadFileCounter);
                addUploadProcessingRow(fsize, uploadFileCounter, file);
                
            },
            onComplete: function (file, response) {
                if (response.indexOf("<pre") >= 0) {
                    response = $(response).text();
                }
                var jsonStr = $.parseJSON(response);                
                //add response from server to file progress
                setResponseOnUploadProgress(jsonStr);
            }
        });

    });
</script>
<script>
    //Declarations
    var itemGridListGlobal = [];

    function ProductProperties() {
        this.nPid =0;
        this.sTocLink ="";
        this.sEulaLink ="";
        this.sExeName ="";
        this.nSizeInBytes =0;
        this.sMD5CheckSum ="";
        this.sAuthorName ="";
        this._isDigitalSigned =false;
        this._isMultilingual =false;
    }

    function ProductImages(){
        this.nPImgid =0;
        this.nPid =0;
        this.sImagePath ="";
        this.sImageThumbPath ="";
        this._isDefaultImg =false;
        this.status =1;
    }

    function editItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            $("#txtUniqueId").val(itemid);
            $("#frmProdProperties").attr("action", approotpath + "Products/ProductProperties");
            $("#frmProdProperties").submit();
        }
    }
    //getVirusDetail():: fetches virus details
    function getCatSubCatProdName(pid) {
        $.ajax(approotpath + "Products/GetProductBreadCrumb", {
            data: {},
            type: "GET",
            dataType: 'json',
            success: function (data) {
                var dataJson = $.parseJSON(data.msgJson);
                alert("GetProductBreadCrumb");
            }
        });
    }

    function getProdImages(pid) {
        if(typeof pid !==undefined && !isNaN(pid) && parseInt(pid)>0){
            var oProduct= new ProductImages();
            oProduct.nPid=pid;
            $.ajax(approotpath + "Helper/GetProductImagesJSON", {
                data: oProduct,
                type: "GET",
                dataType: 'json',
                success: function (data) {
                    bindImages(data);
                    //alert("getProdImages");
                    //console.log(dataJson);
                }
            });
        }
    }

    $(document).ready(function () {
        getProdImages(@(oItemEditDetail!=null?oItemEditDetail.nPid:ViewData["pid"]));
    });

    //remove product image
    function deleteImage(ele) {
        if (confirm("Are you sure want to delete it?")) {
            var pimgd = $(ele).find(".pimgid").val();
            if (typeof pimgd !== undefined && !isNaN(pimgd) && parseInt(pimgd) > 0) {
                var oProduct = new ProductImages();
                oProduct.nPImgid =parseInt(pimgd);
                oProduct.nPid =parseInt($("#txtUniqueId").val());
                $.ajax(approotpath + "Products/DeleteProductImage", {
                    data: oProduct,
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                        if (data.errCode == 250) {
                            $(".img-" + oProduct.nPImgid).remove();
                            alert("Image removed successfully");
                        }
                        //alert("getProdImages");
                        //console.log(dataJson);
                    }
                });
            }
        }
    }
    
</script>

